﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Internet_Cafe.App_Code.DatabaseModel;
using Internet_Cafe.App_Code.DataBaseAccess;

namespace Internet_Cafe
{
    /// <summary>
    /// Interaction logic for EditUser.xaml
    /// </summary>
    public partial class EditUser : Window
    {
        User userForEdit;
        public EditUser(User _userForEdit)
        {
            InitializeComponent();
            userForEdit = _userForEdit;
            txtTitle.Text = userForEdit.Username;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            userForEdit.FirstName = txtEditFirstName.Text;
            userForEdit.LastName = txtEditLastName.Text;
            userForEdit.Username = txtEditUserName.Text;
            userForEdit.Password = txtEditPassword.Text;
            userForEdit.Email = txtEditEmail.Text;
            if (!DbUsersAccess.Update(userForEdit.ID, userForEdit))
            {
                MessageBox.Show("Промената во базата не е успешна", "Неуспешна промена", MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
            }
            else
            {
                MessageBox.Show("Промената во базата е успешна", "Успешна промена", MessageBoxButton.OK, MessageBoxImage.Information);
                this.Close();
            }

        }
    }
}
